package com.learn.training.multithread.chapter11.demo1;

public class UserContext implements AutoCloseable{

    static final ThreadLocal<String> ctx = new ThreadLocal<>();

    public UserContext(String user){
        ctx.set(user);
    }

    public static String currentUser(){
        return ctx.get();
    }

    @Override
    public void close() throws Exception {
        System.out.println("close user context   " + Thread.currentThread().getName());
        ctx.remove();
    }
}
